import 'package:flutter/material.dart';
import 'package:flutter3demo/%E8%BD%AC%E5%9C%BA%E5%8A%A8%E7%94%BB/%E6%8B%96%E6%8B%BDpush%E5%88%B0%E6%96%B0%E9%A1%B5%E9%9D%A2/CustomRoute.dart';

void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: Text('拖拽push到新页面'),
        ),
        body: FirstPage(),
      ),
    );
  }
}

class FirstPage extends StatefulWidget {
  @override
  State<StatefulWidget> createState() {
    return FirstPageState();
  }
}

class FirstPageState extends State<FirstPage> with TickerProviderStateMixin {
  @override
  void initState() {
    print("wqeqwewqe");
    // TODO: implement initState
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('第一个页面'),
      ),
      body: Column(
        mainAxisSize: MainAxisSize.min,
        children: [
          GestureDetector(
            onTap: () {
              Navigator.of(context).push(CustomCupertinoPageRoute(
                  hasNextDragToWidget: true,
                  currentIsDragPush: false,
                  builder: (context) {
                    return SecondPage();
                  }));
            },
            child: Container(
              height: 200,
              width: 100,
              color: Colors.red,
            ),
          ),
          GestureDetector(
            onTap: () {
              Navigator.of(context).push(MaterialPageRoute(
                  barrierDismissible: true,
                  builder: (context) {
                    return GestureDetector(
                        onHorizontalDragStart: (details) {
                          Navigator.of(context).push(MaterialPageRoute(
                              barrierDismissible: true,
                              builder: (context) {
                                return SecondPage();
                              }));
                        },
                        onHorizontalDragUpdate: (_1) {
                          print("wqeqwewqe");
                        },
                        onHorizontalDragEnd: (__) {
                          print("==========");
                        },
                        child: SecondPage());
                  }));
            },
            child: Container(
              height: 200,
              width: 100,
              color: Colors.green,
            ),
          ),
        ],
      ),
    );
  }
}

class SecondPage extends StatefulWidget {
  @override
  State<StatefulWidget> createState() {
    return SecondPageState();
  }
}

class SecondPageState extends State<SecondPage> with TickerProviderStateMixin {
  @override
  void initState() {
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('第二个页面'),
      ),
      body: Column(
        mainAxisSize: MainAxisSize.min,
        children: [
          GestureDetector(
            onTap: () {
              Navigator.of(context).pop();
            },
            child: Container(
              height: 200,
              width: 100,
              color: Colors.green,
            ),
          ),
        ],
      ),
    );
  }
}
